﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebUtils;

namespace OAuth.AuthLocations
{
    public sealed class GetParameter : AuthInfoLocation
    {
        private static GetParameter instance;
        public static GetParameter Instance
        {
            get
            {
                if (instance == null)
                    instance = new GetParameter();
                return instance;
            }
        }

        private GetParameter()
        {
        }

        public override string Name { get { return "GET query parameters"; } }

        public override ISignedWebRequest CreateSignedRequest(IUnsignedWebRequest pUnsignedWebRequest, IEnumerable<UnEncodedURLParameter> pOAuthParameters)
        {
            return new DefaultSignedWebRequest()
            {
                Address = pUnsignedWebRequest.Address,
                GetParameters = AddGetParams(pUnsignedWebRequest.GetParameters, pOAuthParameters),
                Headers = pUnsignedWebRequest.Headers,
                PostParameters = pUnsignedWebRequest.PostParameters,
                UnsignedWebRequest = pUnsignedWebRequest,
                Verb = pUnsignedWebRequest.Verb
            };
        }

        private IEnumerable<UnEncodedURLParameter> AddGetParams(IEnumerable<UnEncodedURLParameter> pGetParams, IEnumerable<UnEncodedURLParameter> pOAuthParameters)
        {
            return pGetParams.Concat(pOAuthParameters);
        }
    }
}
